# -*- coding: utf-8 -*-
"""助手程序，实现一些通用的函数"""

#from zlbaobao.app1 import models

class PageCuter:
	"""通用分页器实用类"""
	__count = 0 # count >= 0
	__pageSize = 10 # pageSize >= 1
	__pageCount = 0 # = count / pageSize + (count % pageSize != 0 and 1 or 0)
	__pageNumber = 1 # pageNumber >= 1 and pageNumber <= pageCount
	__start = 0 # = (pageNumber - 1) * pageSize
	__end = 0 # = start + pageSize

	def __init__(self, count, pageSize, pageNumber=1):
		self.setCount(count)
		self.setPageSize(pageSize)
		self.setPageNumber(pageNumber)

	def isInteger(self,var):
		"""判断变量是不是整数"""
		if type(var) == type(0):
			return True
		else:
			return False

	def setCount(self,count):
		"""设置条目总数"""
		if not (self.isInteger(count) and count >= 0):
			raise Exception("Parameter error","_PageCuter__count must be an Integer that greater than or equal to 0.")
		self.__count = count
		self.__setPageCount(count / self.__pageSize + (count % self.__pageSize != 0 and 1 or 0))

	def getCount(self):
		"""获取总条目数"""
		return self.__count

	def setPageSize(self,pageSize):
		"""设置页面大小"""
		if not (self.isInteger(pageSize) and pageSize >= 1):
			raise Exception("Parameter error","_PageCuter__pageSize must be an Integer that greater than or equal to 1.")
		self.__pageSize = pageSize
		self.__setStart((self.__pageNumber - 1) * pageSize)
		self.__setEnd(self.__start + pageSize)
		self.__setPageCount(self.__count / pageSize + (self.__count % pageSize != 0 and 1 or 0))

	def getPageSize(self):
		"""获取页面大小"""
		return self.__pageSize

	def setPageNumber(self,pageNumber):
		"""设置页码"""
		if not (self.isInteger(pageNumber) and pageNumber >= 1 and pageNumber <= self.__pageCount):
			raise Exception("Parameter error","_PageCuter__pageNumber must be an Integer that greater than or equal to 1, less than or equal to _PageCuter__pageCount.")
		self.__pageNumber = pageNumber
		self.__setStart((pageNumber - 1) * self.__pageSize)
		self.__setEnd(self.__start + self.__pageSize)

	def getPageNumber(self):
		"""获取当前页码"""
		return self.__pageNumber

	def __setPageCount(self,pageCount):
		"""设置页面总数"""
		self.__pageCount = pageCount

	def getPageCount(self):
		"""获取总页数"""
		return self.__pageCount

	def __setStart(self,start):
		"""设置起始下标"""
		self.__start = start
		self.__setEnd(self.__start + self.__pageSize)

	def getStart(self):
		"""获取开始下标"""
		return self.__start

	def __setEnd(self,end):
		"""设置结束下标"""
		self.__end = end

	def getEnd(self):
		"""获取结束下标"""
		return self.__end

if __name__ == "__main__":
	objs = range(0,100)
	pc = PageCuter(0,0)
